/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package air_hockey_v2.gui;

import java.awt.event.MouseEvent;

/**
 *
 * @author Matheus Cintra
 */
public class MouseVelocidade extends Thread {

    private static int[][] pos = new int[2][2];
    private MouseEvent e;
    private static double vx, vy;

    public MouseVelocidade(MouseEvent e) {
        this.e = e;
    }

    public void addPos(int x, int y) {
        pos[0][0] = pos[1][0];
        pos[0][1] = pos[1][1];
        pos[1][0] = x;
        pos[1][1] = y;
    }

    @Override
    public void run() {
        addPos(e.getX(), e.getY());        
        try {
            Thread.sleep(17);
            addPos(e.getX(), e.getY());
            vx = (pos[0][0] - pos[1][0])/5;
            vy = (pos[0][1] - pos[1][1])/5;
        } catch (InterruptedException ex) {
        }
    }

    public synchronized int getVx() {
        return (int)vx;
    }

    public synchronized int getVy() {
        return (int)vy;
    }
}
